﻿using Microsoft.AspNetCore.Mvc;
using NewLife.Caching;

namespace newlife.cache.api.Controllers
{
    /// <summary>
    /// Redis 基础操作
    /// </summary>
    public class RedisCacheBaseController(FullRedis fullRedis) : RedisBaseController(fullRedis)
    {
        [HttpPost]
        public IActionResult Set(string key, string name)
        {
            // 再次赋值则覆盖
            return Ok(FullRedis.Set(key, new { Id = 1, Name = name }, 60));
        }

        [HttpGet]
        public IActionResult Get(string key)
        {
            return Ok(FullRedis.Get<string>(key));
        }

        [HttpGet]
        public IActionResult Expire(string key)
        {
            return Ok(FullRedis.GetExpire(key).TotalSeconds);
        }

        [HttpGet]
        public IActionResult Exists(string key)
        {
            return Ok(FullRedis.ContainsKey(key));
        }

        [HttpGet]
        public IActionResult Count()
        {
            return Ok(FullRedis.Count);
        }

        [HttpGet]
        public IActionResult Keys()
        {
            return Ok(FullRedis.Keys);
        }

        [HttpDelete]
        public IActionResult Remove(string key)
        {
            return Ok(FullRedis.Remove(key));
        }

        [HttpDelete]
        public IActionResult RemoveAll()
        {
            FullRedis.Clear();
            return NoContent();
        }
    }
}
